package cn.supermarket.controller.monitor;

import cn.supermarket.common.annotation.Log;
import cn.supermarket.common.core.controller.BaseController;
import cn.supermarket.common.core.entity.Result;
import cn.supermarket.common.core.page.TableDataInfo;
import cn.supermarket.common.entity.system.SysLogininfor;
import cn.supermarket.common.enums.BusinessType;
import cn.supermarket.common.utils.poi.ExcelUtil;
import cn.supermarket.system.dto.SysLogininforDTO;
import cn.supermarket.system.service.SysLogininforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author yp
 * @Date 2025/2/25:14:26
 */
@RestController
@RequestMapping("/monitor/logininfor")
public class SysLogininforController extends BaseController {
    @Autowired
    private SysLogininforService logininforService;

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLogininforDTO logininfor)
    {
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        return getDataTable(list);
    }

    @Log(title = "登录日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLogininforDTO logininfor)
    {
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
        util.exportExcel(response, list, "登录日志");
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public Result remove(@PathVariable String[] infoIds)
    {
        return toAjax(logininforService.removeById(infoIds));
    }

    @PreAuthorize("@ss.hasPermi('monitor:logininfor:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public Result clean()
    {
        logininforService.remove(null);
        return success();
    }
}
